package com.hxgis.statisticanalysis.intelligentIndicator.controller;

import cn.hutool.json.JSONUtil;
import com.hxgis.statisticanalysis.intelligentIndicator.pojo.WorkOrderTriggerEvent;
import com.hxgis.statisticanalysis.intelligentIndicator.service.WorkOrderTriggerEventService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 赵恒
 * @date 2022/12/19
 */
@RestController
@RequestMapping("/tj/api/IntelligentIndicator")
@Api(tags = {"工单变化触发器（其他用途，前端不管）"})
@Slf4j
public class WorkOrderTriggerEventController {
    @Resource
    WorkOrderTriggerEventService workOrderTriggerEventService;

    @RequestMapping(value = "/triggerEvent/insert", method = RequestMethod.POST)
    public String insert(@RequestBody WorkOrderTriggerEvent workOrderTriggerEvent) {
        log.info("接口/tj/api/IntelligentIndicator/triggerEvent/insert被调用，参数workOrderTriggerEvent：{}", JSONUtil.toJsonStr(workOrderTriggerEvent));
        workOrderTriggerEvent.setInsertTime(new Date());
        boolean b = workOrderTriggerEventService.save(workOrderTriggerEvent);
        if (b) {
            return "添加成功";
        } else {
            throw new RuntimeException("添加失败");
        }
    }

    @RequestMapping(value = "/triggerEvent/list", method = RequestMethod.GET)
    public List<WorkOrderTriggerEvent> list() {
        return workOrderTriggerEventService.list();
    }
}
